package com.uboxol.example.tengu.api;

import com.alibaba.fastjson.JSONObject;
import com.uboxol.cloud.tengu.common.server.annotation.TenguApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * model: tengu
 * API示例接口独立设置
 * @author liyunde
 * @since 2019/9/10 14:47
 */
@Api(tags = "API示例接口独立设置")
@Slf4j
@ResponseBody
@RestController
@RequestMapping("api")
public class IndependentApiController {

    /**
     * 这个接口没有文档描述,也不需要授权
     *
     * @return
     */
    @TenguApi
    @GetMapping("listGoods")
    public JSONObject listGoods() {

        JSONObject jsonObject = new JSONObject();

        jsonObject.put("name", "商品名");
        jsonObject.put("code", "1234567890");

        return jsonObject;
    }

    /**
     * 这个接口有文档,同时接口需要权限
     *
     * @return
     */
    @TenguApi(permission = true)
    @ApiOperation(value = "获取示例信息", notes = "说明接口的详细信息，介绍，用途，注意事项等。", response = JSONObject.class)
    @PostMapping("getJson")
    public Object getJson() {

        JSONObject jsonObject = new JSONObject();

        jsonObject.put("name", "商品名");
        jsonObject.put("code", "1234567890");

        return jsonObject;
    }

    /**
     * 这个接口不会注册,也没有文档
     * @param query
     * @return
     */
    @PostMapping(value = "user/balance/query")
    public WalletResult getBalanceByUid(WalletQuery query) {
        String userId = query.getUserId();

        String balance = " 123.45";

        return new WalletResult("200", "success", balance);
    }

    @Data
    public static class WalletQuery {
        String userId;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class WalletResult {
        String code;
        String message;
        String balance;
    }
}
